"""
    限定次数的循环使用的帧计时器
    FrequencyTimer --> CycleTimer --> OnlyTimer
"""
from PyPixelCore.timer.CycleTimer import CycleTimer


class FrequencyTimer(CycleTimer):
    def __init__(self, max_frame, frequency_number):
        super().__init__(max_frame)
        self.frequency_number = frequency_number
        self.type = 3

    def next_frame(self):
        if not self._is_end:
            self.now_frame += 1
            if self.max_frame < self.now_frame:
                self.now_frame = 0
                self._is_end = True
                self.frequency_number -= 1
                if self.frequency_number < 1:
                    self.type = 0  # 伪装成单次计时器,方便被删除

    def __str__(self):
        return F"FrequencyTimer  |is_end: {self._is_end}  frequency: {self.frequency_number}  max_frame: {self.max_frame}  now_frame: {self.now_frame}"



